package com.pacy.pacybaseproject.activitys.routing;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;


import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.pacy.pacybaseproject.BR;
import com.pacy.pacybaseproject.R;
import com.pacy.pacybaseproject.base.BaseXFragment;
import com.pacy.pacybaseproject.databinding.RoutingTaxiFragmentBinding;
import com.pacy.pacybaseproject.viewmodels.RoutingTaxiViewModel;

import io.reactivex.annotations.Nullable;

/**
 * @author PACY
 * @date 2024/3/4
 * description:
 */
public class RoutingTaxiFragment extends BaseXFragment<RoutingTaxiFragmentBinding, RoutingTaxiViewModel> {
    private BaiduMap mBaiduMap;
    public static RoutingTaxiFragment newInstance(String title) {

        Bundle args = new Bundle();
        args.putString("title", title);
        RoutingTaxiFragment fragment = new RoutingTaxiFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.routing_taxi_fragment;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        mBaiduMap=binding.mapView.getMap();
        initMapState();
    }

    public void initMapState(){
        MapStatus.Builder builder = new MapStatus.Builder();
        builder.zoom(16.0f);
        mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
        //开起交通图
        mBaiduMap.setTrafficEnabled(true);
        //打开地图定位图层
        mBaiduMap.setMyLocationEnabled(true);

        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newLatLng(new LatLng(39.537967,116.685658)));

        //定义Maker坐标点
        LatLng point = new LatLng(39.537967,116.685658);
        //构建Marker图标
        BitmapDescriptor bitmap = BitmapDescriptorFactory
                .fromResource(R.drawable.icon_marker);
        //构建MarkerOption，用于在地图上添加Marker
        OverlayOptions option = new MarkerOptions()
                .position(point)
                .icon(bitmap);
        //在地图上添加Marker，并显示
        mBaiduMap.addOverlay(option);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding.mapView.onDestroy();
    }

    @Override
    public void onPause() {
        super.onPause();
        binding.mapView.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
        binding.mapView.onResume();
    }

    @Override
    public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
        super.onViewStateRestored(savedInstanceState);
        binding.mapView.onSaveInstanceState(savedInstanceState);
    }
}
